<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 将多个变量和函数存储到对象中作为对象的属性和方法
    // ES5 
    /* var name = "张三";
    var age = 18;
    var hobby = "唱歌";
    function say() {
        console.log(this.name, this.age);
    }

    var zhang = {
        name: name,
        age: age,
        hobby: hobby,
        say: say,
    }
    console.log(zhang);
 */

    // ES6 => 对象简写
    // (1)  如果对象的键名和键值对应的变量名相同 => 可以简写  (可以将变量和函数放到{}里面,作为对象的属性和方法)

    var name = "张三";
    var age = 18;
    var hobby = "唱歌";
    function say() {
        console.log(this.name, this.age);
    }

    var zhang = {
        name,
        age,
        hobby,
        say,
    }
    console.log(zhang);

    // (2) 对象中 => 函数可以直接简写 省略:function
    var obj = {
        a: 1,
        b: 2,
        // sum: function () {
        //     return this.a + this.b;
        // }
        sum() {
            return this.a + this.b;
        }
    }
    console.log(obj);







</script>

</html>